<template>
  <div id="app">
    <h2>测试题</h2>
    <subject :arr="list" @sum="addSub"></subject>
    <div>
      <flag :arr="list"></flag>
    </div>
  </div>
</template>

<script>
import subject from "./components/Subject";
import flag from "./components/Flag";
export default {
  components: {
    subject,
    flag,
  },
  data() {
    return {
      list: [
        {
          num1: Math.floor(Math.random() * 11),
          num2: Math.floor(Math.random() * 11),
          status: "未完成",
          show: "",
          click: "",
        },
        {
          num1: Math.floor(Math.random() * 11),
          num2: Math.floor(Math.random() * 11),
          status: "未完成",
          show: "",
          click: "",
        },
        {
          num1: Math.floor(Math.random() * 11),
          num2: Math.floor(Math.random() * 11),
          status: "未完成",
          show: "",
          click: "",
        },
        {
          num1: Math.floor(Math.random() * 11),
          num2: Math.floor(Math.random() * 11),
          status: "未完成",
          show: "",
          click: "",
        },
        {
          num1: Math.floor(Math.random() * 11),
          num2: Math.floor(Math.random() * 11),
          status: "未完成",
          show: "",
          click: "",
        },
      ],
    };
  },
  methods: {
    addSub(i) {
      let he = Number(this.list[i].num1 + this.list[i].num2); // 得到俩个随机数的和
      let value = Number(this.list[i].sumUp); //得到输入的和
      this.list[i].click = true;
      if (he == value) {
        this.list[i].show = true;
        this.list[i].status = "正确";
      } else if (he != value) {
        //判断不等的情况下
        this.list[i].show = false;
        this.list[i].status = "错误";
      }
    },
  },
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>